package com.lgr.store.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lgr.store.dao.SupplierDAO;
import com.lgr.store.utils.PageObject;
import com.lgr.store.vo.SupplierVo;
import javax.annotation.Resource;
import java.util.List;

@Service
public class SupplierService {
    @Resource
    SupplierDAO supplierDAO;

    //列表
    @Transactional
    public List<SupplierVo> list(SupplierVo supplier, PageObject pager){
        List<SupplierVo> supplierList = supplierDAO.listAll(supplier,pager);
        return supplierList;
    }
    //通过id查找数据
    @Transactional
    public SupplierVo getById(int supplierId){
        return supplierDAO.getById(supplierId);
    }
    //新增
    @Transactional
    public void add(SupplierVo supplier){
        supplierDAO.add(supplier);
    }
    //修改
    @Transactional
    public void update(SupplierVo supplier){
        supplierDAO.update(supplier);
    }
    //新增or修改
    @Transactional
    public void saveOrUpdate(SupplierVo supplier){
        if(supplier.getSupplierId()==null){
            add(supplier);
        }else{
            update(supplier);
        }
    }
    //记录数
    @Transactional
    public int supplierCount(){
        return supplierDAO.supplierCount();
    }
    //删除
    @Transactional
    public void supplierDel(int supplierId){
         supplierDAO.supplierDel(supplierId);
    }
}
